home *** CD-ROM | disk | FTP | other *** search
- unit Gifbitmp;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, CCGIF;
-
- type
- TGIFBitmap = class(TComponent)
- private
- { Private declarations }
- FOnLoadGIF : TNotifyEvent;
- FOnCreate : TNotifyEvent;
- FOnDestroy : TNotifyEvent;
- TheGIF : PGIF;
- protected
- { Protected declarations }
- public
- { Public declarations }
- Width : Longint; { Holds the pixel width when done }
- Height : Longint; { Holds the pixel height when done }
- The_Name : String; { Holds the file name }
- TheBMP : TBitmap;
- constructor Create( AOwner : TComponent ); override;
- destructor Destroy; override;
- procedure Load_GIF_File;
- published
- { Published declarations }
- property FileName : String read The_Name write The_Name;
- property OnCreate : TNotifyEvent read FOnCreate write FOnCreate;
- property OnDestroy : TNotifyEvent read FOnDestroy write FOnDestroy;
- property OnLoadGIFFile : TNotifyEvent read FOnLoadGIF write FOnLoadGIF;
- end;
-
- procedure Register;
-
- implementation
-
-
- { This creates a file bitmap object }
- constructor TGIFBitmap.Create( AOwner : TComponent );
- begin
- { call inherited FIRST! }
- inherited Create( AOwner );
- The_Name := '';
- TheBMP := TBitmap.Create;
- if Assigned(FOnCreate) then OnCreate( Self );
- end;
-
- { This is the destructor procedure }
- destructor TGIFBitmap.Destroy;
- begin
- if Assigned(FOnDestroy) then OnDestroy(Self);
- TheBMP.Free;
- { call inherited last }
- inherited destroy;
- end;
-
- procedure TGIFBitmap.Load_GIF_File;
- var thebuffer : array[ 0..255] of char;
- TheGif : PGif;
- begin
- if Assigned(FOnLoadGIF) then OnLoadGIFFile( Self );
- if The_Name = '' then exit;
- if not FileExists( The_Name ) then
- begin
- MessageDlg( The_Name + ' cannot be found!',mterror,[mbOK],0);
- exit;
- end;
- Screen.Cursor := crHourGlass;
- StrPCopy( TheBuffer , The_Name );
- TheGif := NEW( PGif , Init( theBuffer ));
- TheBMP.Width := TheGif^.ImageDescriptor.ImageWidth;
- TheBMP.Height := TheGif^.ImageDescriptor.ImageHeight;
- TheGif^.Decode( false , TheBMP );
- Dispose( TheGif , Done );
- Screen.Cursor := crDefault;
- end;
-
- procedure Register;
- begin
- RegisterComponents('Gadgets', [TGIFBitmap]);
- end;
-
- end.
-